<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="box">hello box</div>
    <script>
      const box = document.getElementById("box");
      console.log(box.style.width); // 为空
      console.log(box.style.height); // 为空

      //---

      const style = getComputedStyle(box);
      console.log(style.width);
      console.log(style.height);

      //---

      console.log(box.offsetWidth);
      console.log(box.offsetHeight);
    </script>
  </body>
</html>
